package org.ww.statistics.scheduled;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.ww.statistics.service.DailyService;
import org.ww.statistics.utils.DateUtil;

import java.util.Date;

@Component
public class ScheduledTask {

    @Autowired
    private DailyService dailyService;

    //每天凌晨1点，把前一天数据进行查询添加
    @Scheduled(cron = "0 0 1 * * ?")  //表达式不能写7位，写7位会报错（虽然叫做七子运算）
    public void task1(){
        dailyService.addStatistics(DateUtil.formatDate(DateUtil.addDays(new Date(), -1)));
    }
}
